package com.example.learn.hwod.并查集;

public class UnionCollect {

    private int count =0;
    private int[] parent;

    public UnionCollect(int count) {
        this.count = count;
        parent= new int[count];
        for (int i = 0; i < count; i++) {
            parent[i] = i;
        }
    }

    public int find(int p){
        while(p!=parent[p]){
            parent[p] = parent[parent[p]];
            p=parent[p];
        }
        return p;
    }

}
